package com.android.danaobank.utils;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.LogUtils;

public class EqualsItemDecoration extends RecyclerView.ItemDecoration {
    public static final int TYPE_GRID = 1;
    public static final int TYPE_LINEAR = 0;
    private int col;
    private int dividerWidth;
    private int type;

    public EqualsItemDecoration(int i, int i2) {
        this.dividerWidth = i;
        this.col = i2;
    }

    public void getItemOffsets(@NonNull Rect rect, @NonNull View view, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.State state) {
        recyclerView.getChildAdapterPosition(view);
        if (this.type == 1) {
            int i = this.dividerWidth;
            int i2 = this.col;
            i = (i * (i2 + 1)) / i2;
            int spanIndex = ((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex() + 1;
            int i3 = i * spanIndex;
            i2 = this.dividerWidth;
            i3 -= spanIndex * i2;
            rect.right = i3;
            rect.left = i - i3;
            rect.bottom = i2;
            LogUtils.e("rect1:" + JSON.toJSON(rect));
            return;
        }
        int spanIndex = this.dividerWidth;
        rect.bottom = spanIndex;
        rect.right = spanIndex;
        rect.left = spanIndex;
        LogUtils.e("rect2:" + JSON.toJSON(rect));
    }

    public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.State state) {
        super.onDraw(canvas, recyclerView, state);
    }

    public void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.State state) {
        super.onDrawOver(canvas, recyclerView, state);
    }

    public void setLayoutType(int i) {
        this.type = i;
    }
}
